define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'equip_rate_mods_apply/index' + location.search,
                    add_url: 'equip_rate_mods_apply/add',
                    edit_url: 'equip_rate_mods_apply/edit',
                    // del_url: 'equip_rate_mods_apply/del',
                    multi_url: 'equip_rate_mods_apply/multi',
                    import_url: 'equip_rate_mods_apply/import',
                    table: 'equip_rate_mods_apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), operate: false },
                        { field: 'user', title: __('Agid'), operate: false },
                        { field: 'pros', title: __('Pro_id'), operate: false },
                        { field: 'sn', title: __('Sn') },
                        { field: 'typs', title: '变更类型', operate: false },
                        { field: 'nums', title: __('Nums'), operate: false },
                        { field: 'orig_rate', title: __('Orig_rate'), operate: 'BETWEEN', operate: false },
                        { field: 'appy_rate', title: __('Appy_rate'), operate: 'BETWEEN', operate: false },
                        { field: 'is_apply', title: '审核状态', searchList: { "1": __('Is_apply 1'), "2": __('Is_apply 2'), "3": __('Is_apply 3') }, formatter: Table.api.formatter.normal },
                        { field: 'takes', title: '生效时间', operate: false },
                        { field: 'status', title: __('Status'), searchList: { "1": __('Status 1'), "2": __('Status 2') }, formatter: Table.api.formatter.status, operate: false },
                        { field: 'appyPhone', title: __('Appyphone'), operate: 'LIKE', operate: false },
                        { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, defaultValue: Controller.api.today(0) + " 00:00:00 - " + Controller.api.today(0) + ' 23:59:59' },
                        { field: 'apply_time', title: '审核时间', operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, operate: false },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, operate: false }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            },

            today: function(AddDayCount) {
                const dd = new Date();
                dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
                let y = dd.getFullYear();
                let m = dd.getMonth() + 1; //获取当前月份的日期
                let d = dd.getDate();
                //判断月
                if (m < 10) {
                    m = "0" + m;
                }
                //判断日
                if (d < 10) {
                    d = "0" + d;
                }
                return y + "-" + m + "-" + d;
            }
        }
    };
    return Controller;
});